/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db.server.BUS;

import db.server.DAO.DesignDAO;
import db.server.DTO.DesignTableDTO;

import java.io.File;

/**
 *
 * @author QuangKhai
 */
public class DesignBUS {
    private DesignDAO designDAO = new DesignDAO();
    
    ///Create a file contain design table
    public void newTable(String path){
        File table = new File(path);
        
        if(!table.exists()){
            table.mkdir();            
        }
    }
    
    ///Call function from DesignTableDAO to save design table
    public void saveDesignTable(DesignTableDTO table, String path){
        for(int i = 0; i < path.length(); i++){
            if(path.charAt(i) == '.'){
                designDAO.writeDesignTable(table, path);
                return;
            }
        }
        
        String filePath =  path + "\\" + table.getTableName();
        newTable(filePath);
        designDAO.writeDesignTable(table, filePath);

    }
    
    ///Call function from DesignTableDAO to get design table
    public DesignTableDTO readDesignTable(String designPath){
        return designDAO.readDesignTable(designPath);
    }
}
